<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue</title>
    <script type="text/javascript" src="../../js/vue.js"></script>
    <style>
        .basic{
            width: 400px;
            height: 100px;
            border: 1px solid black;
        }
        .happy{
            border: 4px solid red;
            background-color: rgba(255, 255, 0, 0.644);
            background: linear-gradient(30deg,yellow,pink,orange,yellow);
        }
        .sad{
            border: 4px solid green;
            background-color:royalblue;
        }
        .nomal{
            border: 4px solid purple;
            background-color :purple;
        }
    </style>
</head>
<body>
    <div id="root">
        <!-- 绑定样式字符串写法，适用于样式的类名不确定，需要动态决定 -->
        <div class="basic" :class="mood" @click="changeMood">
            {{name}}
        </div>
        <br>
        <br>

        <!-- 绑定样式数组写法，适用于样式的个数和名字都确定 需要动态决定用不用-->
        <div class="basic" :class="arr" ></div>

         <!-- 绑定样式对象写法，适用于样式的个数和名字都不确定， -->
         <div class="basic" :class="classObj" ></div>

         <!-- 绑定style样式 -->
         <div class="basic" :style="styleObj" > {{name}}</div>
        
    </div>

    <script type="text/javascript">
        Vue.config.performance = false;
        const vm = new Vue({
            el:'#root',
            data() {
                return {
                  name:'zw',
                  mood:'nomal',
                  arr:['nomal','happy','sad'],
                  classObj:{
                    happy:true,
                    sad:true
                  },
                  styleObj:{
                      fontSize:'40px', // font-size
                      color:'red',
                      backgroundColor:'orange'
                  }
                };
            },
            methods: {
                changeMood() {
                    const arr = ['nomal','happy','sad']
                    let index = Math.floor(Math.random()*3)
                    console.log(index)
                    this.mood = arr[index]
                },
            },
        })

    </script>

</body>
</html>